<?php
namespace Products\Model;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
use Zend\Db\Sql\Predicate;
use Zend\Db\Sql\Expression;

class CountryAndIndustryTable
{
    protected $tableGateway;
	protected $select;
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
		$this->select = new Select();
    }
	public function addData($adddata,$industry,$country)
    {
		if(isset($adddata['hid_industry_id']) && $adddata['hid_industry_id']!=""){
			$this->tableGateway->delete(array('(industry_id IN ('. $adddata['hid_industry_id'].'))'));	
		}
		$data = array(
				'country_id'        		 => $country,
				'industry_id' 	     		 => $industry,	
				'satatus_country_industry' 	 => 1,	
			   );
		$this->tableGateway->insert($data);
		return $this->tableGateway->lastInsertValue;
    }
	public function getCountryIndustries( $countryId ){
		$select = $this->tableGateway->getSql()->select();		
		$select->join('industry', 'country_and_industry.industry_id=industry.industry_id',array('*'),'left');
		$select->where( 'country_and_industry.country_id='. $countryId );
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;
	}
}